package com.wdd.atcrowdfunding.potal.service.impl;

import com.wdd.atcrowdfunding.bean.Member;
import com.wdd.atcrowdfunding.potal.dao.MemberMapper;
import com.wdd.atcrowdfunding.potal.service.MemberService;
import com.wdd.atcrowdfunding.util.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class MemberServiceImpl implements MemberService {

    @Autowired
    private MemberMapper memberMapper;

    public void insertMember(Member member) {
        System.out.println("进入insertMember");
        int insert = memberMapper.insert(member);
        System.out.println(insert);
    }


    public boolean querySelectMemberByLoginacct(String loginacct) {
        if(memberMapper.querySelectMemberByLoginacct(loginacct)==null){
            return false;
        }
        return true;
    }

    public boolean querySelectMemberByEmail(String email) {
        if(memberMapper.querySelectMemberByEmail(email)==null){
            return false;
        }
        return true;
    }

    public Member queryMemberLogin(Map<String, Object> paramMap) {
        Member member = memberMapper.queryMemberLogin(paramMap);
        return member;
    }

    @Override
    public void updateAcctType(Member loginMember) {
        memberMapper.updateAcctType(loginMember);
    }

    @Override
    public void updateBasicinfo(Member loginMember) {
        memberMapper.updateBasicinfo(loginMember);
    }

    @Override
    public void updateEmail(Member loginMember) {
        memberMapper.updateEmail(loginMember);
    }

    @Override
    public void updateAuthstatus(Member loginMember) {
        memberMapper.updateAuthstatus(loginMember);
    }

    @Override
    public Page<Member> queryMemberPage(Map<String, Object> paramMap) {
        Page<Member> page = new Page<Member>((Integer) paramMap.get("pageno"),(Integer) paramMap.get("pagesize"));

        Integer startIndex = page.getStartIndex();
        paramMap.put("startIndex",startIndex);
        List<Member> datas = memberMapper.queryList(paramMap);
        page.setDatas(datas);

        Integer totalsize = memberMapper.queryCount(paramMap);
        page.setTotalsize(totalsize);
        return page;
    }

    @Override
    public Member selectById(Integer id) {
        return memberMapper.selectById(id);
    }
}
